import datetime
import os
import sys

from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium import webdriver

#创建一个浏览器驱动对象
class Driver:
    driver=""

    def __init__(self):
        options=webdriver.EdgeOptions()
        self.driver=webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()),options=options)
        self.driver.implicitly_wait(3)#隐式等待

        #创建屏幕截图
    def getScreenShot(self):
        #子文件夹名称：当天日期
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        #判断该子文件夹是否存在，不存在则建立
        if not os.path.exists("../images/" + dirname):
            os.mkdir("../images/" + dirname)
        #截图文件名用调用方法+日期+时刻
        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S") + ".png"
        self.driver.save_screenshot("../images/" + dirname + "/" + filename)
# 创建一个类的实例
BlogDriver = Driver()